package plus.easydo.server.user.mp.controller;

import cn.hutool.http.HttpUtil;
import com.google.common.collect.Maps;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import plus.easydo.server.user.mp.dto.LoginDto;
import plus.easydo.starter.log.annotation.SystemLog;
import plus.easydo.starter.oauth.resources.anotation.IgnoreThePermissions;

import javax.validation.Valid;


/**
 * @author laoyu
 * @version 1.0
 * @date 2021/7/1
 */
@Api(tags = "登录接口")
@SystemLog("登录接口")
@RestController
@RequestMapping("/login1/")
public class LoginController {

    @Value("${oauth-url:}")
    private String oauthUrl;

    @ApiOperation("账号密码登录")
    @IgnoreThePermissions
    @PostMapping("")
    public String login(@RequestBody @Valid LoginDto dto) {
        String sb = oauthUrl + "/oauth/token?client_id=" +
                dto.getClientId() + "&client_secret=" +
                dto.getSecret() + "&grant_type=password&username=" +
                dto.getUserName() + "&password=" + dto.getPassword();
        return HttpUtil.post(sb, Maps.newHashMap());
    }
}
